﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace wsess.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ValuesController : ControllerBase
    {
        private readonly SessionHelpler _helpler;
        public ValuesController(SessionHelpler helper)
        {
            _helpler = helper;
        }
        // GET api/values
        [HttpGet]
        public ActionResult<string> Get()
        {
            //if(HttpContext.Session.TryGetValue("id", out byte[] cid))
            //{
            //    return Encoding.Default.GetString(cid);
            //}
            //return "empty";
            return _helpler.GetSession("id");
        }

        // GET api/values/5
        [HttpGet("{id}")]
        public ActionResult<string> Get(int id)
        {
            //HttpContext.Session.Set("id", Encoding.Default.GetBytes(id.ToString()));
            //return "value";
            _helpler.SetSession("id", id.ToString());
            return "value";
        }

        // POST api/values
        [HttpPost]
        public void Post([FromBody] string value)
        {
        }

        // PUT api/values/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/values/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}
